package com.icss.flow.controller;

import camundajar.impl.scala.annotation.meta.param;
import com.icss.flow.pojo.dto.ListQueryDTO;
import com.icss.flow.pojo.dto.ParamDTO;
import com.icss.flow.service.CommEntityService;
import org.dromara.common.core.domain.R;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("commonEntity")
public class CommEntityController {
    @Autowired
    private CommEntityService commEntityService;


    /**
     * 通用条件查询实体数据
     * @param queryDTO 条件参数
     * @return
     */
    @PostMapping("/listQuery")
    public TableDataInfo<?> listQuery(@RequestBody ListQueryDTO queryDTO) {
        return commEntityService.listQuery(queryDTO);

    }


    /**
     * 通用新增实体表数据
     * @param entityCode 实体编码code
     * @param param 实体字段键值对
     * @return
     */
    @PostMapping("createEntity")
    public R<?> createEntity(@RequestParam Integer entityCode, @RequestBody Map<String, Object> param) {
        int isSuccess = commEntityService.createEntity(entityCode, param);
        if(isSuccess>0){
           return  R.ok("新增实体表单数据成功");
        }
        return  R.ok("新增实体表单数据失败");

    }

    /**
     * 通用修改实体表数据
     * @param entityCode 实体编码code
     * @param param 实体字段键值对
     * @return
     */
    @PostMapping("updateEntity")
    public R<?> updateEntity(@RequestParam Integer entityCode,@RequestParam Integer id, @RequestBody Map<String, Object> param) {
        if(commEntityService.updateEntity(entityCode,id, param)){
            return  R.ok("修改实体表单数据成功");
        }
        return  R.ok("修改实体表单数据失败");

    }
}
